package cn.zjh.basic.service.impl;

import cn.zjh.basic.mapper.BaseMapper;
import cn.zjh.basic.query.BaseQuery;
import cn.zjh.basic.service.IBaseService;
import cn.zjh.basic.util.PageList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

@Service
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;
    @Override
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public T findOne(Long id) {
        return baseMapper.findOne(id);
    }

    @Override
    public Integer queryCount(BaseQuery baseQuery) {

        return null;
    }

    @Override
    public PageList<T> queryPage(BaseQuery baseQuery) {
        Integer totals = baseMapper.queryCount(baseQuery);
        if (totals ==0){
            return new PageList<>();
        }
        List<T> data = baseMapper.queryData(baseQuery);
        return  new PageList<>(data,totals);
    }

    @Override
    public void patchDel(List<Long> ids) {
        baseMapper.patchDel(ids);
    }
    
}
